package logic

import (
	"context"
	"errors"
	"shop/model/mysql"

	"shop/internal/svc"
	"shop/shop"

	"github.com/zeromicro/go-zero/core/logx"
)

type CollectAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCollectAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectAddLogic {
	return &CollectAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CollectAddLogic) CollectAdd(in *shop.CollectAddRequest) (*shop.CollectAddResponse, error) {
	// todo: add your logic here and delete this line
	var err error
	var c mysql.Collect
	c.UserId = in.UserId
	c.HouseId = in.HouseId
	c.Collects = in.Collects
	if err = c.Create(); err != nil {
		logx.Error("收藏失败")
		return nil, errors.New("收藏失败")
	}
	return &shop.CollectAddResponse{
		Id: int64(c.ID),
	}, nil
}
